package org.nielin.bestwaper.core.filter;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


public final class BackurlUtil
{
	
	private static Map<String, String> idc2url = new ConcurrentHashMap<String, String>();
	private static String backurl_def = "http://bjbu.3g.qq.com/backurl_proxy/bu";
		
	static
	{
		try{
			reloadConfig();
		}catch(Throwable e){
			MyLogger.getNormal().error("", e);
		}
	}
	
	private static void reloadConfig()
	{
		String s = SystemConf.getInstance().getBackurlPorxys();
		String[] ss = StringUtil.split(s, ";");
		for(int i = 0; i < ss.length; ++i){
			String[] sss = StringUtil.split(ss[i], "|");
			if(sss.length < 2)
				continue;
			if(i == 0)
				backurl_def = sss[1];
			idc2url.put(sss[0], sss[1]);
		}
	}
	
	public static boolean isEnableBackurlProxy()
	{
		return SystemConf.getInstance().isEnableBackurlProxy();
	}
	
	public static String getBackurl(String sid)
	{
		return getBackurlBase() + "?sid=" + sid + "&amp;r=" + RandomUtil.getString(3);
	}
	
	private static String getBackurlBase()
	{
		return backurl_def;
	}
	
}
